home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Collections: Topik
/
Topik - Disk 02 - Fonts and CLI Commands (19xx)(Topik Public Domain)(PD)[a][WB].zip
/
Topik - Disk 02 - Fonts and CLI Commands (19xx)(Topik Public Domain)(PD)[a][WB].adf
/
Source
/
speed.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-04-20
|
3KB
|
145 lines
#include <stdio.h>
#include <libraries/dos.h>
#include <exec/memory.h>
#include <exec/exec.h>
#include "libraries/dos.h" /* for requestor turn-off */
#include "libraries/dosextens.h"/* for requestor turn-off */
char * AllocMem();
struct Process *FindTask();
long Read();
long Write();
APTR save_WindowPtr = (APTR) NULL;
/* Place to save the process' pr_WindowPtr while
we disable "requestors" */
/*
Function requestors_off
Description:
Make sure that "requestors" (boxes in the upper left hand corner of the
screen) don't appear.
Inputs:
None.
Outputs:
None.
Global variables used:
Saves the old value of the process' pr_WindowPtr in save_WindowPtr.
*/
void requestors_off()
{
struct Process *o_proc;
o_proc = (struct Process *) FindTask (NULL);
save_WindowPtr = o_proc->pr_WindowPtr;
o_proc->pr_WindowPtr = -1L;
}
/*
Function requestors_restore
Description:
Restores the process' pr_WindowPtr to whatever it was to begin with.
Inputs:
None.
Outputs:
None.
Global variables used:
Gets the old value of the process' pr_WindowPtr from save_WindowPtr.
*/
void requestors_restore()
{
struct Process *o_proc;
o_proc = (struct Process *) FindTask (NULL);
o_proc->pr_WindowPtr = save_WindowPtr;
}
long millisec()
{
/* Returns time in milliseconds since midnite. Changed every 50 ms. */
long DateStamp();
long v[3];
DateStamp(v);
return ( (v[1] * 60000L) + (v[2] * 20L));
}
void main()
{
long f;
char *buff;
long time1, time2, i, iter, size;
long x1, x2;
double ksec;
char s[100];
requestors_off();
printf("Enter block size in Kbytes->"); /* get buffer size for io */
gets(s);
sscanf(s,"%ld\n", &size);
size = size * 1024;
printf("Enter number of iterations ->"); /* get number of iterations */
gets(s);
sscanf(s,"%ld\n", &iter); /* to use buffer per operation */
printf("Block size, interations = %ld, %ld\n", size, iter);
buff = (char *)AllocMem(size, MEMF_CLEAR);
if (buff == 0) { /* alloc failed so exit */
printf("Not enough contigious memory; block size = %ld\n", size);
exit();
}
f = Open("test.file", MODE_NEWFILE);
Forbid();
x1 = millisec();
for (i = 0; i < iter; i++)
{
if (Write(f, buff, size) < size)
{
printf ("Write failed on attempt %d\n", i);
break;
}
}
x2 = millisec();
Permit();
/* the getclk call returns an char array[8], where array[5] is minutes,
array[6] is seconds, and array[7] is hundredths of seconds */
ksec = (double)(((double)(size * iter) / (double)(x2 - x1))
* 1000.0) / 1024.0; /* convert elapsed time to k/second */
printf("elapsed time for write = %ld millisec., K/sec = %10.4f\n",
(x2 - x1), ksec);
Close(f);
Delay(10L); /* give file system time to settle before next test */
/* didn't know if I needed this, but just in case */
f = Open("test.file", MODE_OLDFILE);
x1 = millisec();
for (i = 0; i < iter; i++)
{
if (Read(f, buff, size) < size)
{
printf ("Read failed on attempt %d\n", i);
break;
}
}
x2 = millisec();
ksec = (double)(((double)(size * iter) / (double)(x2 - x1))
* 1000.0) / 1024.0; /* convert elapsed time to k/second */
printf("elapsed time for read = %ld millisec., K/sec = %10.4f\n",
(x2 - x1), ksec);
Close(f);
DeleteFile("test.file"); /* get rid of the temp file */
FreeMem(buff, size);
requestors_restore();
}